<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h2>登录</h2>
<form id="loginForm">
    用户名：<input type="text" id="username"><br>
    密码：<input type="password" id="password"><br>
    <button type="submit">登录</button>
</form>
<p id="msg"></p>

<script>
    $('#loginForm').submit(function (e) {
        e.preventDefault();
        $.ajax({
            url: '/api/login',
            method: 'POST',
            contentType: 'application/json',
            data: JSON.stringify({
                username: $('#username').val(),
                password: $('#password').val()
            }),
            success: function (data) {
                $('#msg').text(data);
            },
            error: function (xhr) {
                $('#msg').text(xhr.responseText);
            }
        });
    });
</script>
</body>
</html>
